package com.ete.service.upload.net.logging

import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

/**
 * 公共请求头拦截设置
 * @author chenxiaojin
 * @date 2023/11/30
 */
class RequestHeaderInterceptor : Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val original = chain.request()
        val requestBuilder = original.newBuilder() // 避免出现 unexpected end of stream on http://xxx问题
            // https://stackoverflow.com/questions/45838774/java-io-ioexception-unexpected-end-of-stream-on-connection-in-android
            .addHeader("Connection", "close")
        val request = requestBuilder.build()
        return chain.proceed(request)
    }
}